package birdsong.client;
import birdsong.comm.ClientComm;
import birdsong.comm.ClientSideMessage;

public class teste extends Thread {

	private ClientComm cliente;
	private ClientSideMessage cliSideMessage;
	private ClientGUI t;

	public teste(ClientComm cliente, ClientGUI t) { 
		this.cliente = cliente;
		this.t = t;
	}

	@Override
	public void run() {
		super.run();
		while (cliente.isConnected()) {
			cliente.hasNextMessage();
			cliSideMessage = cliente.getNextMessage();
			
			switch (cliSideMessage.getType()) {
			
			case CONNECTED:
				t.adicionarClienteConetado(cliSideMessage.getPayload());
				break;
			case DISCONNECTED:
				t.removeUtilizador(cliSideMessage.getPayload());
				break;
			case BIRDSONG_MESSAGE:
				System.out.println(" teste - recebeu mensagem");
				t.adicionaNovaMensagem( cliSideMessage.getSendersNickname(), cliSideMessage.getPayload());
				break;
			case FOLLOWER:
				t.adicionaFollowed(cliSideMessage.getPayload());
				break;
			case UNFOLLOWER:
				t.removeFollowed(cliSideMessage.getPayload());
				break;
			default:
				break;
			}
		}
	}
}
